#!/bin/bash

APP=`dirname $0`/sql_to_csv

if [ $# -lt 2 ]; then
   echo "Usage: $0 <output_dir> <trace_1> [trace2 ... traceN]"
   exit 2
fi

outdir="$1"
shift

while [ $# -gt 0 ]; do
   base=`basename $1 | sed s/\.sq3$//`
   kvm=`echo $1 | grep -e -kvm.sq3$`
   xen=`echo $1 | grep -e -xen.sq3$`
   dump=`echo $1 | grep -e -dump.sq3$`

   # Extract job records for all run types
   $APP "$1" "$outdir/$base-jobs.csv" raw_jobs

   if [ -z "$dump" ]; then
      # Extract the trace data and grid-level scheduling data
      $APP "$1" "$outdir/$base-trace.csv" trace
      $APP "$1" "$outdir/$base-grid_sched.csv" grid_sched
      #
      if [ -n "$kvm" -o -n "$xen" ]; then
         $APP "$1" "$outdir/$base-grid_voc.csv" grid_voc
      fi
   fi
   shift
done
